﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DuelQuizz.contract;
using DuelQuizzServer;

namespace DuelQuizz.Views
{
    /// <summary>
    /// Logique d'interaction pour LeaderboardPage.xaml
    /// </summary>
    public partial class LeaderboardPage : UserControl
    {
        private MainPage main_page;
        private Leaderboard leaderboard;

        public struct Row
        {
            public BitmapImage image { set; get; }
            public string rank { set; get; }
            public string username { set; get; }
        }


        public LeaderboardPage(MainPage main_page)
        {
            this.main_page = main_page;
            InitializeComponent();

            leaderboard = AppServices.getDuelQuizzServices().getLeaderBoard();

            switch (leaderboard.current_position)
            {
                case 1: label_classement.Content = "Vous êtes 1er"; break;
                default: label_classement.Content = "Vous êtes " + leaderboard.current_position + "eme"; break;
            }

            //player_list.ItemsSource = leaderboard.leaderboard;


            foreach (KeyValuePair<int,User> row in leaderboard.leaderboard)
            {
                BitmapImage b = new BitmapImage(new Uri("pack://application:,,,/assets/avatar.png"));
                b.DecodePixelWidth = 30;
                string rank = "";
                if (row.Key == 1)
                    rank = row.Key + "er - " + row.Value.score + " pt";
                else
                    rank = row.Key + "eme - " + row.Value.score + " pt";

                player_list.Items.Add(new Row { image = b, rank = rank, username = row.Value.username });

            }

        }

        private void Button_Click_Retour(object sender, RoutedEventArgs e)
        {
            MainWindow.changeWindows(main_page);
        }
    }
}
